home *** CD-ROM | disk | FTP | other *** search
- Path: news.ov.com!news
- From: glenn@ov.com (Fletcher.Glenn@ov.com)
- Newsgroups: comp.lang.c
- Subject: Re: Why doesn't this work?
- Date: 7 Mar 1996 16:46:31 GMT
- Organization: OpenVision
- Message-ID: <4hn3t7$rvt@spanky.pls.ov.com>
- References: <1996Mar4.161412.137442@forest>
- Reply-To: glenn@ov.com
- NNTP-Posting-Host: foghorn.pls.ov.com
-
- In article 137442@forest, ebromber@forest.drew.edu writes:
- >Does anyone know why this password program doesn't work properly? And if
- >you do know the problem how can I fix it? It rejects every password including
- >the real password. The program was compiled using a MS-DOS compiler.
- >Thanks in advance.
- >ebromber@drew.edu
- >
- >main();
- >{ char real[4];
- > char pass[100];
- > int count=0;
- > int i, error;
- > char c;
- > real[0]='j';real[1]='e';real[2]='r';real[3]='k';
- > printf("PASSWORD: ");
- > fflush(stdout);
- > while (c=getch() !='\n')
- > { count++;
- > pass[count]=c;
-
- Replace the two lines above with:
- pass[count++] = c;
- Otherwise, your first password character goes into pass[1].
-
- > putch('*');
- > }
- > if (count!=4) { printf("\nWRONG PASSWORD\n"); main();}
- > error=0;
- > for (i=0; i<4; i++)
- > if (real[i]=pass[i]) error++;
- ^
- This is an assignment not a test. You really want '!='.
-
- > if (error>0) {printf("\nWRONG PASSWORD\n"); main();}
- >}
- >
-
- Lastly, why do you recursively call main on error?
-
- Fletcher.Glenn@ov.com
-
-